<%@ page pageEncoding="utf-8"%> 
<%@page import="java.sql.*"%>
<%@page import="java.util.*"%>
<%@page import="com.course.db.*"%>

<%
	String footer = (String)session.getAttribute("SearchStuPageFooter");
	request.setAttribute("layout","main.jsp");
	request.setAttribute("page_title","温岭选课系统-选课管理");
	List<Hashtable<String, String>> course_list = (List<Hashtable<String, String>>) session.getAttribute("AdminCourseList");
	Iterator<Hashtable<String, String>> course_it = course_list.iterator();
	List<Hashtable<String, String>> student_list = (List<Hashtable<String, String>>) session.getAttribute("AdminStudentList");
	Iterator<Hashtable<String, String>> student_it = student_list.iterator();
	
	String studentname = (String)session.getAttribute("studentname");
	String grade = (String)session.getAttribute("grade");
	String selectstatus = (String)session.getAttribute("selectstatus");
	System.out.println("grade:"+grade+" selectstatus:"+selectstatus);
 %>
	<link href="css/jquery.ui.tabs.css" rel="stylesheet">
	<link href="css/jquery.ui.theme.css" rel="stylesheet">
	<link href="css/div_win.css" rel="stylesheet"> 
	<script src="js/div_win.js"></script>
	<script src="js/jquery-1.5.2.min.js"></script>
	<script src="js/jquery-ui-1.8.11.custom.min.js"></script>
	<script src="js/jquery.ui.tabs.js"></script>
	<script type="text/javascript" src="js/popup.js"></script>
	
	<script>
	function getArgs(strParame) {
        var args = new Object( );
        var query = location.search.substring(1);



        var pairs = query.split("&"); // Break at ampersand
        for(var i = 0; i < pairs.length; i++) {
        var pos = pairs[i].indexOf("="); 
        if (pos == -1) continue; 
        var argname = pairs[i].substring(0,pos); 
        var value = pairs[i].substring(pos+1); 
        value = decodeURIComponent(value); 
        args[argname] = value; 
        }
        return args[strParame]; 
        }
	
	$(function() {
		$( "#tabs" ).tabs({selected:getArgs("tab")});
	});
	
	function edit(courseId){
	   $.ajax({
			url: base_path+"Admin/edit.do",
			type: "POST",
			data: {"method":"measuring"},
            data: {"courseId":courseId}, 
			beforeSend: function(XMLHttpRequest){
			},
			success: function(data, textStatus){
				if(data=="success"){
				
				}else{ 
				
				}
			},

			complete: function(XMLHttpRequest, textStatus){	
				ShowIframe('编辑课程信息',base_path+"admin/courseEdit.jspx?courseId=+id",700,600);				
			},
			error: function(){
				$("#ajaxResult").html("服务器异常，请联系网络管理员");
			}
		});
   }
	
	function changestatus(courseId,type){
		   $.ajax({
				url: base_path+"Admin/changeStatus.do",
				type: "POST",
	            data: {"courseId":courseId,"type":type}, 
				beforeSend: function(XMLHttpRequest){
					if(type=='check')
						return confirm("确定要更改课程状态为开课中吗？");
					else
						return confirm("确定要更改课程状态为选课中吗？");
				},
				success: function(data, textStatus){
					if(data=="success"){
					
					}else{ 
					
					}
				},

				complete: function(XMLHttpRequest, textStatus){
					alert("修改成功！");
					window.location.href=base_path+"Admin/courseList.do";
				},
				error: function(){
					$("#ajaxResult").html("服务器异常，请联系网络管理员");
				}
			});
	   }
	function downgrade(){
		   $.ajax({
				url: base_path+"Admin/grades.do",
				type: "POST",
				beforeSend: function(XMLHttpRequest){
					
				},
				success: function(data, textStatus){
					if(data=="student"){
						//alert("删除用户"+username+"成功");
						ShowIframe('编辑学生信息',base_path+"admin/editStudent.jspx",500,300);
					}
				},

				complete: function(XMLHttpRequest, textStatus){
					ShowIframe('下载班级课表',base_path+"admin/downGradeCourse.jspx",500,300);
				},
				error: function(){
					$("#ajaxResult").html("服务器异常，请联系网络管理员");
				}
			});
	   }
	function coursesign(){
		   $.ajax({
				url: base_path+"Admin/Courses.do",
				type: "POST",
				complete: function(XMLHttpRequest, textStatus){
					ShowIframe('下载课程安排表',base_path+"admin/CourseSign.jspx",500,300);
				},
				error: function(){
					$("#ajaxResult").html("服务器异常，请联系网络管理员");
				}
			});
	   }
	function teachercourse(){
		   $.ajax({
				url: base_path+"Admin/grades.do",
				type: "POST",
				complete: function(XMLHttpRequest, textStatus){
					ShowIframe('下载课程安排表',base_path+"admin/daycourse.jspx",500,300);
				},
				error: function(){
					$("#ajaxResult").html("服务器异常，请联系网络管理员");
				}
			});
	   }
	function gradeteacher(){
		   $.ajax({
				url: base_path+"Admin/grades.do",
				type: "POST",
				complete: function(XMLHttpRequest, textStatus){
					ShowIframe('下载教师点到表',base_path+"admin/dayteacher.jspx",500,300);
				},
				error: function(){
					$("#ajaxResult").html("服务器异常，请联系网络管理员");
				}
			});
	   }
	function gradecourse(){
		   $.ajax({
				url: base_path+"Admin/grades.do",
				type: "POST",
				complete: function(XMLHttpRequest, textStatus){
					ShowIframe('下载年级课表',base_path+"admin/gradecourse.jspx",500,300);
				},
				error: function(){
					$("#ajaxResult").html("服务器异常，请联系网络管理员");
				}
			});
	   }
	</script>
<div style="width:100%; margin:1px;text-align:center;margin-top:5px;margin-bottom:20px;">
 	
 	<p style="border:0;font-size:14px;padding-bottom:0;text-align:center;">
 	<!-- 	<b>课程申报记录</b>
  		<select>
  			<option value="全部">全部</option>
  			<option value="2011年第一学期">2011年第一学期</option>
  			<option value="2011年第二学期">2011年第二学期</option>
  			<option value="2012年第一学期">2012年第一学期</option>
  		</select>
	 -->
	</p>
	  <div id="tabs" style="width:90%;margin-left:5%;">
		<ul>
			<li><a href="#tabs-1">课程视图</a></li>
			<li><a href="#tabs-2">学生视图</a></li>
			<li><a href="#tabs-3">报表操作</a></li>
		</ul>
<div id="tabs-1" style="width:100%;margin-left:0;padding-left:0;margin-top:20px;">
	<table>
		<tbody>
		<tr height="32" bgcolor="#f0f0f0">
		   <td align="center" width="7%">课程编号</td>
		   <td align="center" width="8%">课程类型</td>
		   <td align="center" width="8%">课程名称</td>
		   <td align="center" width="8%">授课老师</td>
           <td align="center" width="10%">上课时间|地点</td>
           <td align="center" width="6%">学分</td>
           <td align="center" width="6%">人数限额<br>(最少/最多)</td>
		   <td align="center" width="6%">已选人数<br>
           <td align="center" width="6%">课程状态</td>
		   <td align="center" width="15%">操作</td>
		 </tr>
		<%
            course_it = course_list.iterator();
		    while(course_it.hasNext())
			{
				Hashtable<String, String> cousrelist_hash  = course_it.next();
		%>
		 <tr height="25" bgcolor="#ffffff">
		    <td align="center"><%=cousrelist_hash.get("classno") %></td>
		    <td align="center"><%=cousrelist_hash.get("type") %></td>
		    <td align="center"><%=cousrelist_hash.get("name") %></td>
		    <td align="center"><%=cousrelist_hash.get("teachers") %></td>
		    <td align="center"><%=cousrelist_hash.get("teach_time") %> | <%=cousrelist_hash.get("teach_location") %></td>
		    <td align="center"><%=cousrelist_hash.get("credit") %></td>
		    <td align="center"><%=cousrelist_hash.get("students_low") %>/<%=cousrelist_hash.get("students_high") %></td>
		   	<td align="center"><%=cousrelist_hash.get("num_of_students") %></td>
		    <td align="center">
		    	<% if(cousrelist_hash.get("checkstatus").equalsIgnoreCase("0")){%>
			       	审核中
				<% }else if(cousrelist_hash.get("checkstatus").equalsIgnoreCase("1")){ %>
				 	 审核通过
				<%}else if(cousrelist_hash.get("checkstatus").equalsIgnoreCase("2")){ %>
				  	审核不通过
				<%}else if(cousrelist_hash.get("checkstatus").equalsIgnoreCase("3")){ %>
				 	选课中
				<%}else if(cousrelist_hash.get("checkstatus").equalsIgnoreCase("4")){ %>
				  	开课
				<%}else if(cousrelist_hash.get("checkstatus").equalsIgnoreCase("5")){ %>
				 	 结束
				<%} %>
		    </td>
		    <td align="center">
		    	<a href="Admin/selectdetail.do?courseId=<%=cousrelist_hash.get("Id")%>" class="approve" >查看</a> &nbsp;|&nbsp;
		    <%if(cousrelist_hash.get("checkstatus").equalsIgnoreCase("3")){ %>
		     	<a href="javascript:changestatus(<%=cousrelist_hash.get("Id") %>,'check')" class="approve"  >确定</a>
		     <%}else if(cousrelist_hash.get("checkstatus").equalsIgnoreCase("4")){ %>
		     	<a href="javascript:changestatus(<%=cousrelist_hash.get("Id") %>,'uncheck')" class="approve"  >取消</a>
		     <%} %>
			</td>
		</tr>
		<%} %>
		</tbody>
 	</table>
  </div>
  <div id="tabs-2" style="width:100%;margin-left:0;padding-left:0;margin-top:20px;">
  <form action="Search/searchStudent.do?src=admin" method="post">
  		<table  style="border:0px solid gray;align:middle;width:70%;margin-left:15%; margin-top:10px; margin-bottom:20px">
  			<tr>
  				<td>学生姓名</td>
  				<td>
  					<input type=text style="width:100px;" name="studentname" <%if(studentname!=null){ %> value="<%=studentname %>"<%} %> />
  				</td> 
  				<td>选课状态</td>
  				<td>
  					<select style="width:130px;" name="selectstatus">
 					<% if(selectstatus!=null && selectstatus.trim().equalsIgnoreCase("全部")){%>
 						<option value="全部" selected>全部</option>
 					<% }else {%>
 						<option value="全部">全部</option>
 					<% }if(selectstatus!=null && selectstatus.trim().equalsIgnoreCase("未选")){%>
 						<option value="未选" selected>未选</option>
 					<% }else {%>
 						<option value="未选">未选</option>
 					<% }if(selectstatus!=null && selectstatus.trim().equalsIgnoreCase("已选")){%>
 						<option value="已选" selected>已选</option>
 					<% }else {%>
 						<option value="已选">已选</option>
 					<%} if(selectstatus!=null && selectstatus.trim().equalsIgnoreCase("已审核")){%>
 						<option value="已审核" selected>已审核</option>
 					<%} else {%>
 						<option value="已审核">已审核</option>
 						<%} %>
  					</select>
  				</td>
  				<td>&nbsp;&nbsp;年级</td>
  				<td>
  					<select style="width:130px;" name="grade">
 					<% if(grade!=null && grade.trim().equalsIgnoreCase("全部")){%>
 						<option value="全部" selected>全部</option>
 					<% }else {%>
 						<option value="全部">全部</option>
 					<% }if(grade!=null && grade.trim().equalsIgnoreCase("高一")){%>
 						<option value="高一" selected>高一年级</option>
 					<% }else {%>
 						<option value="高一">高一年级</option>
 					<% }if(grade!=null && grade.trim().equalsIgnoreCase("高二")){%>
 						<option value="高二" selected>高二年级</option>
 					<% }else {%>
 						<option value="高二">高二年级</option>
 					<%} if(grade!=null && grade.trim().equalsIgnoreCase("高三")){%>
 						<option value="高三" selected>高三年级</option>
 					<%} else {%>
 						<option value="高三">高三年级</option>
 						<%} %>
 					</select>
  				</td>
  				<td><input type="submit" value="查询"/></td>
  			</tr>
  		</table>
  </form>
	<table style="border:0px solid gray;align:middle;width:90%;margin-left:5%;">
		<tbody>
		<tr height="32" bgcolor="#f0f0f0">
		   <td align="center" width="7%">学号</td>
		   <td align="center" width="8%">班级</td>
		   <td align="center" width="8%">姓名</td>
           <td align="center" width="6%">选课状态</td>
		   <td align="center" width="10%">操作</td>
		 </tr>
		 <%
            student_it = student_list.iterator();
		    while(student_it.hasNext())
			{
				Hashtable<String, String> studentlist_hash  = student_it.next();
		%>
		 <tr height="25" bgcolor="#ffffff">
		    <td align="center"><%=studentlist_hash.get("no") %></td>
		    <td align="center"><%=studentlist_hash.get("grade") %></td>
		    <td align="center"><%=studentlist_hash.get("name") %></td>
		    <td align="center"><%="" %><%=studentlist_hash.get("selectstatus") %></td>
		    <td align="center">
		    	<a href="Admin/studentSelect.do?studentId=<%=studentlist_hash.get("Id") %>" class="approve" >查看</a>
		    </td>
		</tr>
		<%} %>
		</tbody>
 	</table>
 	<br>
	<%
		if(footer!=null)
    		out.println(footer);
    %>
  </div>
  <div id="tabs-3" style="width:100%;margin-left:0;padding-left:0;margin-top:20px;">
	 <p style="border:0;font-size:14px;padding-bottom:0;">
  	 	<b>导出报表</b>
  	 </p>
  	 <div><a href="javascript:downgrade()">[班级课程表]</a>&nbsp;&nbsp;&nbsp;&nbsp;
  	 <a href="javascript:coursesign()">[学生签到表]</a>&nbsp;&nbsp;&nbsp;&nbsp;
  	 <a href="javascript:teachercourse()">[教师课表]</a>&nbsp;&nbsp;&nbsp;&nbsp;
  	 <a href="javascript:gradeteacher()">[教师到位表]</a>&nbsp;&nbsp;&nbsp;&nbsp;
  	 <a href="javascript:gradecourse()">[年级课表]</a>&nbsp;&nbsp;&nbsp;&nbsp;
  	 </div>
  </div>
 </div>
</div>

